<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<script type="text/javascript">
    var orderHealthEditor = new baidu.editor.ui.Editor();
	$(function() {

		$('#admin_order_health_datagrid').datagrid({
			url : '${pageContext.request.contextPath}/orderHealthController/datagrid.action',
			fit : true,
			fitColumns : true,
			border : false,
			pagination : true,
			idField : 'id',
			pageSize : 10,
			pageList : [ 10, 20, 30, 40, 50 ],
			sortName : 'createTime',
			sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : false,
			nowrap : false,
			frozenColumns : [ [ {
				field : 'id',
				title : '编号',
				checkbox : true
			}, {
				field : 'orderId',
				title : '订单号',
				sortable : true
			}, {
				field : 'cardId',
				title : '卡号',
				sortable : true
			} ] ],
			columns : [ [ {
				field : 'name',
				title : '姓名',
				sortable : true
			}, {
				field : 'createTime',
				title : '创建时间',
				sortable : true
			}, {
				field : 'mobile',
				title : '手机号',
				sortable : true
			}, {
				field : 'statusName',
				title : '状态',
				sortable : true
			},
			{
				field : 'cid',
				title : '身份证号',
				sortable : true
			},
			{
				field : 'bornDate',
				title : '出生日期',
				sortable : true
			},
			{
				field : 'genderName',
				title : '性别',
				sortable : true
			},
			{
				field : 'serviceTime',
				title : '申请服务时间',
				sortable : true
			},
			{
				field : 'hospital',
				title : '保健机构',
				sortable : true
			},
			{
				field : 'department',
				title : '科室',
				sortable : true
			},
			{
				field : 'isUrgentName',
				title : '是否紧急',
				sortable : true
			},
			{
				field : 'isIndependenceName',
				title : '是否能独立行动',
				sortable : true
			},
			{
				field : 'action1',
				title : '查看详情/修改',
				align : 'center',
				formatter : function(value, row, index) {
				    return formatString('<img onclick="admin_order_health_editFun(\'{0}\');" src="{1}"/ title="查看详情/修改">', row.id, '${pageContext.request.contextPath}/style/images/extjs_icons/pencil.png');
				}
			}]],
			toolbar : [ {
				text : '添加订单',
				iconCls : 'icon-add',
				handler : function() {
					admin_order_health_appendFun();
				}
			}]
		});

	});

	function admin_order_health_searchFun() {
		$('#admin_order_health_datagrid').datagrid('load', serializeObject($('#admin_order_health_searchForm')));
	}
	
	function admin_order_health_cleanFun() {
		$('#admin_order_health_searchForm input').val('');
		$('#admin_order_health_datagrid').datagrid('load', {});
	}
	
	function admin_order_health_editFun(id) {
		$('#admin_order_health_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
		var index = $('#admin_order_health_datagrid').datagrid('getRowIndex', id);
		var rows = $('#admin_order_health_datagrid').datagrid('getRows');
		var o = rows[index];
		var data=dataResult(o.status,'${pageContext.request.contextPath}/orderHealthController/save_or_submit.action','${pageContext.request.contextPath}/orderHealthController/edit.action',
				'${pageContext.request.contextPath}/orderHealthController/cancel.action')
		$('<div/>').dialog({
			href : '${pageContext.request.contextPath}/admin/order_health_edit.jsp',
			width : 800, height : 768, modal : true, title : '修改订单信息', buttons : data,
			onClose : function() {$(this).dialog('destroy');},
			onLoad : function() {
				$('#admin_order_health_editForm').form('load', o);
				//给服务项目赋值
				var formObj = $("#admin_order_health_editForm");
				//给baidu ueditor赋值
				orderHealthEditor.render("orderHealthDetailsEditor");
				orderHealthEditor.addListener("ready",function(){
					orderHealthEditor.setContent(formObj.find("input[name='serviceDetails']").val());
    			});
			}
		});
	}

	function currency(url,_this){
		var formObj = $("#admin_order_health_editForm");
		formObj.find("input[name='serviceDetails']").val(orderHealthEditor.getContent());
		$('#admin_order_health_editForm').form('submit', {
			url : url,
			success : function(result) {
				tsResult(result,'admin_order_health_datagrid','.window-body','edit',_this)
			}
		});
	}

	function admin_order_health_appendFun() {
		$('#admin_order_health_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
		$('<div/>').dialog({
			href : '${pageContext.request.contextPath}/admin/order_health_add.jsp',
			width : 600,
			height : 500,
			modal : true,
			title : '添加订单',
			buttons : [ {
				text : '保存',
				iconCls : 'icon-add',
				handler : function() {
					var formObj = $("#admin_order_health_addForm");
					var serviceTimeObj = formObj.find("input[name='serviceTime']");
					if(serviceTimeObj.val()=='') {
						$.messager.alert('错误','请填写申请服务时间！');
						return;
					}
					var d = $(this).closest('.window-body');
					$('#admin_order_health_addForm').form('submit', {
						url : '${pageContext.request.contextPath}/orderHealthController/add.action',
						success : function(result) {
							try {
								var r = $.parseJSON(result);
								if (r.success) {
									$('#admin_order_health_datagrid').datagrid('load',{sort : 'createTime', order : 'desc'});
									d.dialog('destroy');
								}
								$.messager.show({
									title : '提示',
									msg : r.msg
								});
							} catch (e) {
								$.messager.alert('提示', result);
							}
						}
					});
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			}
		});
	}
</script>
<div class="easyui-layout" data-options="fit : true,border : false">
	<div data-options="region:'north',title:'查询条件',border:false" style="height:220px" align="center">
		<form id="admin_order_health_searchForm">
			<table class="tableForm">
			    <tr>
					<th style="width: 170px;">订单号(可模糊查询)</th>
					<td><input name="orderId" style="width: 315px;" /></td>
				</tr>
				<tr>
					<th style="width: 170px;">卡号(可模糊查询)</th>
					<td><input name="cardId" style="width: 315px;" /></td>
				</tr>
				<tr>
					<th style="width: 170px;">姓名(可模糊查询)</th>
					<td><input name="name" style="width: 315px;" /></td>
				</tr>
				<tr>
					<th style="width: 170px;">手机号(可模糊查询)</th>
					<td><input name="mobile" style="width: 315px;" /></td>
				</tr>
				<tr>
					<th>创建时间</th>
					<td><input name="createTimeStart" onFocus="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" />至<input name="createTimeEnd" onFocus="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" /></td>
				</tr>
			</table>
			<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="admin_order_health_searchFun();">过滤</a> <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" onclick="admin_order_health_cleanFun();">取消过滤</a>
		</form>
	</div>
	<div data-options="region:'center',border:false">
		<table id="admin_order_health_datagrid"></table>
	</div>
</div>